package com.itboye.boyeshoping.util.sputil;

import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Build;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;

import com.itboye.boyeshoping.MyApplication;


/**
 * Created by itboye on 2017/4/18.
 */

public class MyPermission {

    /**
     * 单个权限
     * @param activity
     * @param permission    权限名称
     */
    public static void CheckPermission(Activity activity, String permission) {
        if (Build.VERSION.SDK_INT >= 23) {
            int checkCallPhonePermission = ContextCompat.checkSelfPermission(MyApplication.app, permission);
            if (checkCallPhonePermission != PackageManager.PERMISSION_GRANTED) {
                //判断是否需要 向用户解释，为什么要申请该权限
                if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)){

                }
                ActivityCompat.requestPermissions(activity, new String[]{permission}, 1);
                return;
            } else {

            }
        } else {

        }
    }

    public static void mayRequestLocation(Activity activity) {
        if (Build.VERSION.SDK_INT >= 23) {
            int checkCallPhonePermission = ContextCompat.checkSelfPermission(MyApplication.app, Manifest.permission.READ_PHONE_STATE);
            if(checkCallPhonePermission != PackageManager.PERMISSION_GRANTED){
                //判断是否需要 向用户解释，为什么要申请该权限
                if(ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.READ_PHONE_STATE)){
                    //    Toast.makeText(this,R.string.ble_need_location, Toast.LENGTH_LONG).show();
                }

                ActivityCompat.requestPermissions(activity ,new String[]{Manifest.permission.READ_PHONE_STATE},1);
                return;
            }else{

            }
        } else {

        }
    }
}
